package com.lwj.liwanjia.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * token存储
 */

public class SpfUtils {
    private static SpfUtils spfUtils = null;
    private SharedPreferences spf;
    private SharedPreferences.Editor editor;

    public SpfUtils(Context context) {
        spf = context.getSharedPreferences("token", Context.MODE_ENABLE_WRITE_AHEAD_LOGGING);
        editor = spf.edit();
    }

    public static SpfUtils getSpfUtils(Context context) {
        if (spfUtils == null) {
            synchronized (SpfUtils.class) {
                if (spfUtils == null) {
                    spfUtils = new SpfUtils(context);
                }
            }
        }
        return spfUtils;
    }

    public String getToken() {
        return spf.getString("token", "");
    }

    public void setStoken(String token) {
        editor.putString("token", token);
        editor.commit();
    }

    /**
     * 保存省份
     *
     * @param province
     */
    public void setProvince(String province) {
        editor.putString("province", province);
        editor.commit();
    }

    public String getProvince() {
        return spf.getString("province", "浙江省");
    }

    /**
     * 保存市
     *
     * @param city
     */
    public void setCity(String city) {
        editor.putString("city", city);
        editor.commit();
    }

    public String getCity() {
        return spf.getString("city", "杭州市");
    }

    /**
     * 保存区
     *
     * @param district
     */
    public void setDistrict(String district) {
        editor.putString("district", district);
        editor.commit();
    }

    public String getDistrict() {
        return spf.getString("district", "市辖区");
    }

    public void setLatitude(Float latitude) {
        editor.putFloat("latitude", latitude);
        editor.commit();
    }

    public Float getLatitude() {
        return spf.getFloat("latitude", 0);
    }

    public void setLongitude(Float longitude) {
        editor.putFloat("longitude ", longitude);
        editor.commit();

    }

    public Float getLongitude() {
        return spf.getFloat("longitude ", 0);
    }

    public void setGwcNumber(int number) {
        editor.putInt("number", number);
        editor.commit();
    }

    public int getGwcNumber() {
        return spf.getInt("number", 0);
    }

    /**
     * 是否第一次打开app
     *
     * @param firstOpen
     */
    public void FirstOpen(boolean firstOpen) {
        editor.putBoolean("first", firstOpen);
        editor.commit();
    }

    public boolean getFirstOpen() {
        return spf.getBoolean("first", true);
    }

    /**
     * 保存当前未读消息数量
     */
    public void setBadgeCoount(int count) {
        editor.putInt("badge", count);
        editor.commit();
    }

    public int getBadgeCount() {
        return spf.getInt("badge", 0);
    }
}
